1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| #include <bits/stdc++.h> #define ll long long using namespace std; const long long mod = 998244353;
struct node { int opt; ll a1, a2, a3, a4; node(ll x1, ll x2, ll x3, ll x4, ll x5) { this->opt = x1; this->a1 = x2; this->a2 = x3; this->a3 = x4; this->a4 = x5; } node(int x) { this->opt = x; } node() {} };
struct matrix { ll a1, a2, a3, a4; matrix() {} matrix(ll x1, ll x2, ll x3, ll x4) { this->a1 = x1; this->a2 = x2; this->a3 = x3; this->a4 = x4; } };
matrix mul(matrix a, matrix b) { matrix tmp; tmp.a1 = (a.a1 * b.a1 % mod + a.a2 * b.a3 % mod) % mod; tmp.a2 = (a.a1 * b.a2 % mod + a.a2 * b.a4 % mod) % mod; tmp.a3 = (a.a3 * b.a1 % mod + a.a4 * b.a3 % mod) % mod; tmp.a4 = (a.a3 * b.a2 % mod + a.a4 * b.a4 % mod) % mod; return tmp; }
int main() { int n, m; cin >> n >> m; node ins[n + 1]; deque<pair<int, matrix>> dq;
for (int i = 1; i <= n; i++) { int opt; cin >> opt; if (opt != 3) { ll x1, x2, x3, x4; cin >> x1 >> x2 >> x3 >> x4; ins[i] = node(opt, x1, x2, x3, x4); } else ins[i] = node(opt); }
for (int i = 1; i <= m; i++) { int opt; cin >> opt; if (opt == 1) { int index; cin >> index; int new_opt; cin >> new_opt; if (new_opt == 3) { ins[index] = node(3); } else { ll x1, x2, x3, x4; cin >> x1 >> x2 >> x3 >> x4; ins[index] = node(new_opt, x1, x2, x3, x4); } } else { int l, r; cin >> l >> r; int cnt = 1; for (int j = l; j <= r; j++) { if (ins[j].opt == 1) { dq.push_front(pair<int, matrix>(cnt++, matrix(ins[j].a1, ins[j].a2, ins[j].a3, ins[j].a4))); } else if (ins[j].opt == 2) { dq.push_back(pair<int, matrix>(cnt++, matrix(ins[j].a1, ins[j].a2, ins[j].a3, ins[j].a4))); } else { if (dq.size() != 0) { if (dq.front().first > dq.back().first) dq.pop_front(); else dq.pop_back(); } } } if (dq.size() == 0) { cout << 1 << ' ' << 0 << ' ' << 0 << ' ' << 1 << endl; } else { matrix tmp = dq.front().second; dq.pop_front(); while (dq.size() != 0) { tmp = mul(tmp, dq.front().second); dq.pop_front(); } cout << tmp.a1 << " " << tmp.a2 << " " << tmp.a3 << " " << tmp.a4 << endl; } } } system("pause"); }
|